{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "85f7e0dd",
   "metadata": {},
   "source": [
    "# ZeroMQ 基础"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "397f405e",
   "metadata": {},
   "source": [
    "如何解释 ZeroMQ？有些人从它所做的一切美妙的事情开始说起。它是强化版的套接字。它就像带路由的邮箱。它非常快！其他人则试图分享他们顿悟的时刻，那种 zap-pow-kaboom 般顿悟的范式转换时刻，当一切变得显而易见时。事情变得简单起来。复杂性消失了。它开阔了思维。还有些人通过比较来解释。它更小、更简单，但看起来依然熟悉。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8c881bb5",
   "metadata": {},
   "outputs": [],
   "source": [
    "import anywidget\n",
    "import traitlets\n",
    "\n",
    "class CounterWidget(anywidget.AnyWidget):\n",
    "    _esm = \"\"\"\n",
    "    function render({ model, el }) {\n",
    "      let button = document.createElement(\"button\");\n",
    "      button.innerHTML = `count is ${model.get(\"value\")}`;\n",
    "      button.addEventListener(\"click\", () => {\n",
    "        model.set(\"value\", model.get(\"value\") + 1);\n",
    "        model.save_changes();\n",
    "      });\n",
    "      model.on(\"change:value\", () => {\n",
    "        button.innerHTML = `count is ${model.get(\"value\")}`;\n",
    "      });\n",
    "      el.classList.add(\"counter-widget\");\n",
    "      el.appendChild(button);\n",
    "    }\n",
    "    export default { render };\n",
    "    \"\"\"\n",
    "    _css = \"\"\"\n",
    "    .counter-widget button { color: white; font-size: 1.75rem; background-color: #ea580c; padding: 0.5rem 1rem; border: none; border-radius: 0.25rem; }\n",
    "    .counter-widget button:hover { background-color: #9a3412; }\n",
    "    \"\"\"\n",
    "    value = traitlets.Int(0).tag(sync=True)\n",
    "\n",
    "w = CounterWidget(value=42)\n",
    "w"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "py313",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
